package ${package.Controller};

import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
<#--import ${package}.PageResult;-->
<#--import ${package}.Result;-->
import lombok.extern.slf4j.Slf4j;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ${author}
 * @description ${table.comment} 控制器
 * @create ${date}
 */

@Slf4j
@RestController
@Tag(name = "${table.comment}管理")
@RequestMapping("${controllerMappingHyphen}")
public class ${table.controllerName} {

    private final ${table.serviceName} ${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)};

    public ${table.controllerName}(${table.serviceName} ${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}) {
        this.${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)} = ${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)};
    }

    @GetMapping("list")
    @Operation(summary = "查询所有")
    public Result<List<${entity}>> list() {
        return Result.success(${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}.list());
    }

    @GetMapping("page")
    @Operation(summary = "分页查询")
    public Result<PageResult<${entity}>> getPage(long current, long size) {
        return Result.success(${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}.page(new Page<>(current, size), new QueryWrapper<${entity}>()
                .orderByDesc("create_time")));
    }

    @GetMapping("getById/{id}")
    @Operation(summary = "根据ID查询")
    public Result<${entity}> getById(@PathVariable("id") Integer id) {
        return Result.success(${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}.getById(id));
    }

    @PostMapping("save")
    @Operation(summary = "新增")
    public Result<Boolean> save(@RequestBody ${entity} ${(entityFirstLower)!((entity?uncap_first)!'param')}) {
        return Result.success(${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}.save(${(entityFirstLower)!((entity?uncap_first)!'param')}));
    }

    @PutMapping("update")
    @Operation(summary = "修改")
    public Result<Boolean> update(@RequestBody ${entity} ${(entityFirstLower)!((entity?uncap_first)!'param')}) {
        return Result.success(${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}.updateById(${(entityFirstLower)!((entity?uncap_first)!'param')}));
    }

    @DeleteMapping("deleteById/{id}")
    @Operation(summary = "根据ID删除")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return Result.success(${table.serviceName?substring(0,1)?lower_case}${table.serviceName?substring(1)}.removeById(id));
    }
}